<script src="<?php echo $baseurl?>public/ckeditor/ckeditor.js"></script>
<script src="<?php echo $baseurl?>public/ckeditor/adapters/jquery.js"></script>


<div class="row">
	<div class="col-lg-12">
		<h1 class="page-header"><?php echo $project->project_name;?></h1>
	</div>
	<!-- /.col-lg-12 -->
	
</div>

<div class="row">
	<div class="col-lg-12">
		<div class="panel panel-default">
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-8">
                     <form role="form" method="POST" action="">
    

        <div class="form-group">
            <label>Tên module công việc</label>
            <input class="form-control" name="module_name" value="<?php echo $task->module_name; ?>" type="text" >
            <!--<p class="help-block"></p>-->
        </div>
        <div class="form-group">
            <label>Nội dung</label>
            <textarea class="form-control" rows="6" name="content" id="content"><?php echo $task->content; ?></textarea>
            <span class="error_notice" ><?php echo form_error('content'); ?> </span>
        </div>
        <div class="form-group">
            <label>Người thực hiện</label><br>
            
            <?php echo $fview->multiSelectChosen($arrUser, $arraySelected,'users','fullname'); ?>
            <span class="error_notice" ><?php echo form_error('users[]'); ?> </span>
        </div>
		
		<div class="form-group">
            <label>Chuyển người thực hiện</label><br>
			<select class="form-control choose-user-change">
				<option value="">Chọn 1 người</option>
				<?php foreach( $arrayChangeUser AS $el=>$le ){ ?> 
					<option value="<?php echo $le->id;?>"><?php echo $le->name;?></option>
				<?php } ?>
			</select>
			<br/>
			<select style="display:none" class="form-control choose-user-join">
				<option value="">Chọn 1 người</option>
				<?php foreach( $arrUser AS $el=>$le ){ ?> 
					<option value="<?php echo $le['id'];?>"><?php echo $le['fullname'];?></option>
				<?php } ?>
			</select>
		</div>
		
        <div class="form-group">
            <label>Thời gian bắt đầu</label>
            <input class="form-control" name="time_start" id="time_start" type="text" style="width:17% !important" value="<?php echo date("d/m/Y",strtotime($task->time_start)); ?>">
            <span class="error_notice" ><?php echo form_error('time_start'); ?> </span>
        </div>
        <div class="form-group">
            <label>Thời gian kết thúc</label>
            <input class="form-control" name="time_end" id="time_end" type="text" style="width:17% !important" value="<?php echo date("d/m/Y",strtotime($task->time_end)); ?>" >
            <span class="error_notice" ><?php echo form_error('time_end'); ?> </span>    
        </div>
        <div class="form-group">
                                <label>Trạng thái</label>
                                <?php $s_arr = array(
                                        '0' => 'Chưa hoạt động', 
                                        '1' => 'Đang xử lý', 
                                        '2' => 'Đã hoàn thành'); 
                                echo $fview->selectOption($s_arr, $task->status, 'form-control status', 'status');?> 
                            </div>
							
		 <button type="submit" class="btn btn-outline btn-primary">Cập nhật</button>					
    </form>
 </div>
                    <!-- /.col-lg-12 -->
                </div>
                <!-- /.row -->
            </div>
            <!-- /.panel-body -->
        </div>
	</div>
	<!-- /.col-lg-12 -->
	
</div>

<script type="text/javascript"> 
	$( document ).ready(function() {
		$( "#time_start" ).datepicker({ dateFormat: 'dd/mm/yy' });
		$( "#time_end" ).datepicker({ dateFormat: 'dd/mm/yy' });
	});
  
	$('.choose-user-change').change(function(){
		var userchange = $('.choose-user-change').val();
		//alert(userchange);
		if( userchange != null && userchange != '' ){
			$('.choose-user-join').css('display','block');
			$('.choose-user-join').change(function(){
				var userjoin = $('.choose-user-join').val();
				if( userjoin != null && userjoin != '' && userjoin != userchange ){
					var r = confirm("Bạn chắc chắn muốn chuyển người thực hiện công việc này!");
					if (r == true) {
						$.ajax({
							type: 'GET',
							url: "<?php echo site_url() ;?>" + 'change-user',
							data: ({userchange: userchange,userjoin:userjoin,module_id:<?php echo $task->id; ?>}),
							success: function(data) 
							{
								alert(data);
								return false;
								window.location.reload();                 
							},
						});
						
					} else {
						$('.choose-user-join').val('');
					}
				}
			});
		}else{
			$('.choose-user-join').css('display','none');
		}
	});
  
</script>

<script type="text/javascript">
        CKEDITOR.replace( 'content', {  enterMode : CKEDITOR.ENTER_BR, shiftEnterMode : CKEDITOR.ENTER_BR } );
        CKEDITOR.on( 'instanceReady', function( ev )
        {
         ev.editor.dataProcessor.writer.setRules( 'br',
         {
            indent : false,
            breakBeforeOpen : false,
            breakAfterOpen : false,
            breakBeforeClose : false,
            breakAfterClose : false
  });
  });
</script>

